package com.liujit.upms.controller;

import com.liujit.common.domain.params.BaseParams;
import com.liujit.common.domain.result.PageBean;
import com.liujit.upms.domain.params.SysDictParams;
import com.liujit.upms.domain.query.SysDictQuery;
import com.liujit.upms.domain.result.SysDictResult;
import com.liujit.upms.service.SysDictService;
import com.liujit.validator.group.AddGroup;
import com.liujit.validator.group.ModifyGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 系统字典管理接口
 * @Author liujun
 * @Date 2021-07-02 14:51:52
 */
@RequiredArgsConstructor
@Api(tags = "系统字典管理接口")
@RestController
@RequestMapping("/sys/dict")
public class SysDictController {

    private final SysDictService sysDictService;

    @ApiOperation(value = "分页查询", notes = "根据系统字典分页查询条件，分页查询系统字典列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "系统字典分页查询条件", dataType = "SysDictQuery", dataTypeClass = SysDictQuery.class, paramType = "query") })
    @GetMapping("/getPage")
    public PageBean<SysDictResult> getPage(SysDictQuery query) {
        return sysDictService.getPage(query);
    }

    @ApiOperation(value = "添加", notes = "根据系统字典添加请求参数，添加系统字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统字典添加请求参数", dataType = "SysDictParams", dataTypeClass = SysDictParams.class, paramType = "body") })
    @PostMapping("add")
    public Boolean add(@RequestBody @Validated(AddGroup.class) SysDictParams params) {
        return sysDictService.save(params);
    }

    @ApiOperation(value = "修改", notes = "根据系统字典修改请求参数，修改系统字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统字典修改请求参数", dataType = "SysDictParams", dataTypeClass = SysDictParams.class, paramType = "body") })
    @PostMapping("/modify")
    public Boolean modify(@RequestBody @Validated(ModifyGroup.class) SysDictParams params) {
        return sysDictService.save(params);
    }

    @ApiOperation(value = "查询", notes = "根据系统字典id，查询系统字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "系统字典id", dataType = "Long", dataTypeClass = Long.class, paramType = "query") })
    @GetMapping("/get")
    public SysDictResult get(Long id) {
        return sysDictService.get(id);
    }

    @ApiOperation(value = "查询详情", notes = "根据系统字典id，查询系统字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "系统字典id", dataType = "Long", dataTypeClass = Long.class, paramType = "query") })
    @GetMapping("/getDetail")
    public SysDictResult getDetail(Long id) {
        return sysDictService.getDetail(id);
    }

    @ApiOperation(value = "删除", notes = "根据系统字典删除请求参数，删除系统字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统字典删除请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/del")
    public Boolean del(@RequestBody BaseParams params) {
        return sysDictService.del(params);
    }

    @ApiOperation(value = "启用", notes = "根据系统字典启用请求参数，启用系统字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统字典启用请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/enabled")
    public Boolean enabled(@RequestBody BaseParams params) {
        return sysDictService.enabled(params);
    }

    @ApiOperation(value = "禁用", notes = "根据系统字典禁用请求参数，禁用系统字典")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统字典禁用请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/disabled")
    public Boolean disabled(@RequestBody BaseParams params) {
        return sysDictService.disabled(params);
    }

    @ApiOperation(value = "查询条数", notes = "根据系统字典名称，查询系统字典条数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "系统字典id", dataType = "Long", dataTypeClass = Long.class, paramType = "query"),
            @ApiImplicitParam(name = "name", value = "系统字典名称", dataType = "String", dataTypeClass = String.class, paramType = "query") })
    @GetMapping("/getCountByName")
    public Integer getCountByName(Long id, String name) {
        return sysDictService.getCountByName(id, name);
    }

    @ApiOperation(value = "查询条数", notes = "根据系统字典编号，查询系统字典条数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "系统字典id", dataType = "Long", dataTypeClass = Long.class, paramType = "query"),
            @ApiImplicitParam(name = "name", value = "系统字典名称", dataType = "String", dataTypeClass = String.class, paramType = "query") })
    @GetMapping("/getCountByCode")
    public Integer getCountByCode(Long id, String code) {
        return sysDictService.getCountByCode(id, code);
    }

    @ApiOperation(value = "查询列表", notes = "查询系统字典列表")
    @GetMapping("/getList")
    public List<SysDictResult> getList() {
        return sysDictService.getList();
    }
}
